home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / DTS.Draw / TGroupObj.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-17  |  4.5 KB  |  162 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        TGroupObj.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1992 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* See the files "=How to write your app" and "=Using TreeObj.c" for information
  20. ** on this function. */
  21.  
  22. /* The group object is used as a parent of objects that are to be grouped.
  23. ** By having a group parent object, the children are understood to be grouped.
  24. ** This allows a hierarchy of groups.
  25. **
  26. ** Group objects can't be clicked on.  Their members can, however.  This means
  27. ** that hit-testing for a group always returns false.  When an actual object is
  28. ** hit, it actually returns itself only if the parent isn't a group.  A hit on
  29. ** an actual object causes the object to look at the parent.  If the parent is
  30. ** a group, then it wants to return the parent as the object hit.  If in turn that
  31. ** parent is a group, it continues up the chain until a non-group object is hit.
  32. ** For this sample application the first non-group parent will always be the root
  33. ** object.
  34. **
  35. ** The above parent check for hit-testing means that the highest order object
  36. ** in the group will always be returned, thus indicating that all members of the
  37. ** group should be considered selected.  That is the exact implementation we use.
  38. **
  39. ** This also means that only objects directly off the root can be selected.  The
  40. ** object will either be the highest order group object, or it will be an actual
  41. ** object directly off the root.
  42. **
  43. ** It seems kind of odd that a group object can be selected, but it can't be hit.
  44. ** This does actually make sense, since if any one of the members of the group is
  45. ** hit, the entire group should be considered a single entity, and the highest
  46. ** order group object would then naturally be the object to select. */
  47.  
  48.  
  49.  
  50. /*****************************************************************************/
  51.  
  52.  
  53.  
  54. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  55. #include "App.protos.h"        /* Get the prototypes for the application.        */
  56.  
  57. #ifndef __OSEVENTS__
  58. #include <OSEvents.h>
  59. #endif
  60.  
  61. #ifndef __OSUTILS__
  62. #include <OSUtils.h>
  63. #endif
  64.  
  65. #ifndef __QUICKDRAW__
  66. #include <Quickdraw.h>
  67. #endif
  68.  
  69. #ifndef __STRING__
  70. #include <String.h>
  71. #endif
  72.  
  73. #ifndef __TREEOBJ2__
  74. #include "TreeObj2.h"
  75. #endif
  76.  
  77. #ifndef __UTILITIES__
  78. #include "Utilities.h"
  79. #endif
  80.  
  81.  
  82.  
  83.  
  84. #pragma segment DrawObjects
  85. long    TGroupObj(TreeObjHndl hndl, short message, long data)
  86. {
  87. #if VH_VERSION
  88.     char    *cptr;
  89.     Rect    rct;
  90. #endif
  91.  
  92.     switch (message) {
  93.         case FREEMESSAGE:        /* For these messages, the TRect behavior is what we want. */
  94.         case COPYMESSAGE:
  95.         case UNDOMESSAGE:
  96.         case CONVERTMESSAGE:
  97.         case FREADMESSAGE:
  98.         case FWRITEMESSAGE:
  99.         case HREADMESSAGE:
  100.         case HWRITEMESSAGE:
  101.         case GETOBJRECTMESSAGE:
  102.         case SETOBJRECTMESSAGE:
  103.         case SECTOBJRECTMESSAGE:
  104.         case GETBBOXMESSAGE:
  105.         case CLICKMESSAGE:
  106.         case SETSELECTMESSAGE:
  107.         case GETSELECTMESSAGE:
  108.         case COMPAREMESSAGE:
  109.             return(TRectObj(hndl, message, data));
  110.             break;
  111.  
  112.         case INITMESSAGE:
  113.             break;
  114.  
  115.         case HITTESTMESSAGE:
  116.             return(0L);                /* Groups can not directly be hit. */
  117.             break;
  118.  
  119.         case GETRGNMESSAGE:
  120.             return((long)NewRgn());    /* The region is used for hit-testing, so return an empty rgn. */
  121.             break;
  122.  
  123.         case DRAWMESSAGE:
  124.             if (data == DRAWSELECT)
  125.                 TRectObj(hndl, message, data);
  126.                     /* Draw the selection indicators, bu the group has no body. */
  127.             break;
  128.  
  129. #if VH_VERSION
  130.         case VHMESSAGE:
  131.             cptr = ((VHFormatDataPtr)data)->data;
  132.             ccatchr(cptr, 13, 2);
  133.             ccat   (cptr, "$10: TGroupObj:");
  134.             ccatchr(cptr, 13, 1);
  135.             ccat   (cptr, "  $00: selected = ");
  136.             ccatdec(cptr, mDerefGroup(hndl)->selected);
  137.             ccatchr(cptr, 13, 1);
  138.             
  139.             rct = mDerefGroup(hndl)->group;
  140.             ccat      (cptr, "  $02: group    = ($");
  141.             ccatpadhex(cptr, 0, 4, 4, rct.top);
  142.             ccat      (cptr, ",$");
  143.             ccatpadhex(cptr, 0, 4, 4, rct.left);
  144.             ccat      (cptr, ",$");
  145.             ccatpadhex(cptr, 0, 4, 4, rct.bottom);
  146.             ccat      (cptr, ",$");
  147.             ccatpadhex(cptr, 0, 4, 4, rct.right);
  148.             ccat      (cptr, ")");
  149.             return(true);
  150.             break;
  151. #endif
  152.  
  153.         default:
  154.             break;
  155.     }
  156.  
  157.     return(noErr);
  158. }
  159.  
  160.  
  161.  
  162.